Page({
    data: {
        logistics_company: '',
        logistics_number: '',
        tel: '',
        policy: '',
        img_fileList: [],
        video_fileList: []
    },
    onLoad: function(options) {

    },
    Image_afterRead(event) {
        const { file } = event.detail;
        let { img_fileList = [] } = this.data;
        file.forEach(item => {
            img_fileList.push(item);
        })
        this.setData({ img_fileList });
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        // wx.uploadFile({
        //     url: 'https://example.weixin.qq.com/upload',
        //     filePath: file.url,
        //     name: 'file',
        //     formData: { user: 'test' },
        //     success(res) {
        //         // 上传完成需要更新 fileList
        //         const { fileList = [] } = this.data;
        //         fileList.push({ ...file, url: res.data });
        //         this.setData({ fileList });
        //     },
        // });
    },
    delete_image(e) {
        let { img_fileList = [] } = this.data;
        img_fileList.splice(e.detail.index, 1);
        this.setData({ img_fileList });

    },
    video_afterRead(event) {
        // const { url } = event.detail.file
        // let { video_fileList = [] } = this.data
        // video_fileList.push(url)
        // this.setData({ video_fileList })
    },
    upload() {
        const {
            logistics_company,
            logistics_number,
            tel,
        } = this.data
        if (!logistics_company) {
            return wx.showToast({
                title: '请输入物流公司',
                icon: 'none'
            })
        }
        if (!logistics_number) {
            return wx.showToast({
                title: '请输入物流编号',
                icon: 'none'
            })
        }
        if (!tel) {
            return wx.showToast({
                title: '请输入联系电话',
                icon: 'none'
            })
        }
        if (tel) {
            const reg = /^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/
            if (!reg.test(tel)) {
                return wx.showToast({
                    title: '请输入正确的手机号码',
                    icon: 'none'
                })
            }
        }
    }
})